<template>
	<view style="padding: 40rpx;">
		<view class="bg-img bg-mask flex align-center"
			style="background-image: url('https://t.mwm.moe/fj/');height: 414upx;">
			<view class="padding-xl text-white">
				<view class="padding-xs text-xxl text-bold">
					{{name}}
				</view>
				<view class="padding-xs text-lg">
					<view>{{amount}}元</view>
					<view>{{msg}}</view>
				</view>
			</view>
		</view>
		<radio-group class="block" @change="RadioChange">
				
				<view class="cu-form-group">
					<view class="title">余额</view>
					<radio class='radio' :class="radio=='A'?'checked':''" :checked="radio=='A'?true:false" value="A"></radio>
				</view>
				<view class="cu-form-group">
					<view class="title">支付宝</view>
					<radio class='radio' :class="radio=='B'?'checked':''" :checked="radio=='B'?true:false" value="B"></radio>
				</view>
				
			</radio-group>
		<button class="cu-btn block bg-blue margin-tb-sm lg"  @click="zhifu">
			<text class="cuIcon-goodsfavor"></text>
			支付
		</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				token:'',
				name: '',
				amount: 0,
				msg: '',
				radio: 'A',
				rs:''
			}
		},
		onLoad(e) {
			this.token = uni.getStorageSync("token")
			if(this.token == ''){
				uni.showToast({
					title: '请先登录',
					icon:"error"
				});
				uni.navigateTo({
					url: '../login/login'
				});
			}
			this.name = e.name
			this.amount = e.amount
			this.msg = e.msg
		},
		methods: {
			RadioChange(e) {
			    this.radio = e.detail.value
				console.log(e.detail.value);
			},
			zhifu(){
				if(this.radio == 'A'){
					uni.request({
						url: 'http://127.0.0.1:9000/user/balance?balance='+this.amount,
						header:{"Authorization":this.token},
						method: 'POST',
						success(res) {
							console.log(res);
							if(res.data.code==200){
								uni.showToast({
									title: '支付成功',
									icon:'success'
								});
								uni.navigateTo({
									url: 'member',
									success: res => {},
									fail: () => {},
									complete: () => {}
								});
							}else{
								uni.showToast({
									title: res.data.message,
									icon:'error'
								});
							}
						}
					});
				}else{
					uni.request({
						url: 'http://127.0.0.1:9000/user/topupzf?topup='+this.amount,
						method: 'POST',
						header:{"Authorization":this.token},
						data: {
							
						},
						success(res) {
							this.rs = res.data.data.返回页面
							console.log(this.rs);
						}
						
					})
					uni.showToast({
						title: '缺失信息，联系商家添加key!',
						icon:"error"
					});
				}
			}
		}
	}
</script>


<style>
	page {
		background-color: white;

	}
</style>
